/**
 * 
 */
package com.gordon.tips.action;

import java.io.IOException;

import com.gordon.tips.domain.User;
import com.gordon.tips.log.Logger;
import com.gordon.tips.log.LoggerImpl;
import com.gordon.tips.util.OperateImage;
import com.gordon.tips.util.ReadResource;

/**
 *****************************************************************************
 ** Module : Crop the image
 ** 
 ** Date:  2011-10-11
 ** 
 ** Author: Gordon
 ** 
 ** Email: 462991284@qq.com
 ** 
 ** (C) Copyright 2011 Gordon Office
 *****************************************************************************
 */

public class CropAction extends BaseAction {
	//Cropping Coordinate.width and height
	private int x;
	private int y;
	private int w;
	private int h;
	
	//target file name
	private String targetFileName;
	
	private static Logger logger = new LoggerImpl(CropAction.class);
	
	public String cropImage()
	{
		logger.debug("x:"+x);
		logger.debug("y:"+y);
		logger.debug("w:"+w);
		logger.debug("h:"+h);
		
		User user=(User) session.get("user_session");
		int id=user.getId();
		OperateImage o  =   new  OperateImage( x , y , w, h);
		
		//handle the src file
		String targetFolder=ReadResource.getProperties("projectPath");
		String srcPath=targetFolder+targetFileName;
		o.setSrcpath(srcPath);
		
		//handle the ext
		String ext="";
		logger.debug("targetFileName:"+targetFileName);
		if(targetFileName.contains("."))ext=targetFileName.substring(targetFileName.indexOf("."));
		
		//handle the target file
		String disFileName="a"+id+ext;
		logger.debug("disFileName:"+disFileName);
		o.setSubpath(targetFolder+disFileName);
		try {
			o.cut();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return "updateAvatarComplete";
	}
	
	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}
	public int getW() {
		return w;
	}
	public void setW(int w) {
		this.w = w;
	}
	public int getH() {
		return h;
	}
	public void setH(int h) {
		this.h = h;
	}

	public String getTargetFileName() {
		return targetFileName;
	}

	public void setTargetFileName(String targetFileName) {
		this.targetFileName = targetFileName;
	}
	
	

}
